<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html" 
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets">

    <body>

        <ui:composition template="./templates/basicTemplate.xhtml">
            <ui:define name="content">
                <h:form id="new_user">                       
                    <p:panelGrid columns="2">
                        <f:facet name="header">
                            <h:outputText value="Přidat uživatele"/>                            
                        </f:facet>
                        <h:outputLabel value="Jméno:" for="name" />
                        <p:inputText validatorMessage="Prosím vyplňte jméno (minimálně 2 znaky, maximálně 15 znaků)" id="name" value="#{newUserForm.name}" required="true">
                            <f:validateLength minimum="2" maximum="15"/>
                        </p:inputText>

                        <h:outputLabel value="Přijmení:" for="surname" />
                        <p:inputText validatorMessage="Prosím vyplňte přijmení (minimálně 2 znaky, maximálně 15 znaků)" id="surname" value="#{newUserForm.surname}" required="true">
                            <f:validateLength minimum="2" maximum="15"/>
                        </p:inputText>

                        <h:outputLabel value="Email:" for="email" />
                        <p:inputText validatorMessage="Nesprávný formát emailu" id="email" value="#{newUserForm.email}" required="true">
                            <f:validateRegex pattern="^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$" />
                        </p:inputText>

                        <h:outputLabel for="pwd1" value="Heslo:" />  
                        <p:password validatorMessage="Hesla se musí shodovat, Zadejte heslo (5 - 20 znaku)" id="pwd1" value="#{newUserForm.password}" match="pwd2" required="true">
                            <f:validateLength minimum="5" maximum="20"/>
                        </p:password>
                        <h:outputLabel for="pwd2" value="Heslo znovu:" />  
                        <p:password id="pwd2" validatorMessage="Heslo ma byt 5 - 20 znaku dlouhe." value="#{newUserForm.password}" required="true"/>


                        <h:outputLabel value="Role" for="role" />
                        <p:selectOneMenu value="#{newUserForm.role}" id="role">
                            <f:selectItems value="#{user.userRoles}" var="role" itemLabel="#{role}" itemValue="#{role}"/> 
                            <p:ajax event="change" update="category"/>
                        </p:selectOneMenu>

                        <h:outputLabel value="Sledované kategorie" for="category" />
                        <p:selectManyMenu value="#{newUserForm.categories}" id="category" disabled="#{newUserForm.disableCategories}">
                            <f:selectItems value="#{category.categories}" var="cat" itemLabel="#{cat.name}" itemValue="#{cat.id}"/>                            
                        </p:selectManyMenu>

                        <f:facet name="footer">
                            <p:commandButton value="Uložit" action="#{newUserForm.saveUser()}" update="new_user"/>
                        </f:facet>
                    </p:panelGrid>
                </h:form>
            </ui:define>

        </ui:composition>

    </body>
</html>
